home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Integers / Range.cp < prev    next >
Text File  |  1997-06-28  |  2KB  |  78 lines

  1. // Range.cp
  2.  
  3. #ifndef Range_h
  4. #include "Range.h"
  5. #endif
  6. #ifndef MinMax_h
  7. #include "MinMax.h"
  8. #endif
  9.  
  10. template < class Value >
  11. void Range<Value>::operator&=( const RangeType& r )
  12.   {
  13.     start = Max( start, r.start );
  14.     end = Min( end, r.end );
  15.   }
  16.  
  17. template < class Value >
  18. void Range<Value>::operator|=( const RangeType& r )
  19.   {
  20.     start = Min( start, r.start );
  21.     end = Max( end, r.end );
  22.   }
  23.  
  24. template < class Value >
  25. Range<Value> Range<Value>::operator&( const RangeType& r ) const
  26.   {
  27.     RangeType result( *this );
  28.     result &= r;
  29.     return result;
  30.   }
  31.  
  32. template < class Value >
  33. Range<Value> Range<Value>::operator|( const RangeType& r ) const
  34.   {
  35.     RangeType result( *this );
  36.     result |= r;
  37.     return result;
  38.   }
  39.  
  40. template < class Value >
  41. void Range<Value>::ExtendToContain( Value v )
  42.   {
  43.     Assert( Value( v+1 ) > v );
  44.     start = Min( start, v );
  45.     end = Max( end, Value( v+1 ) );
  46.   }
  47.  
  48. template < class Value >
  49. void Range<Value>::ExtendToWeaklyContain( Value v )
  50.   {
  51.     start = Min( start, v );
  52.     end = Max( end, v );
  53.   }
  54.  
  55. template < class Value >
  56. void Range<Value>::ExtendToStrictlyContain( Value v )
  57.   {
  58.     Assert( Value( v+1 ) > v );
  59.     Assert( Value( v-1 ) < v );
  60.     start = Min( start, Value( v-1 ) );
  61.     end = Max( end, Value( v+1 ) );
  62.   }
  63.  
  64. template < class Value >
  65. void Range<Value>::ExtendToReverseContain( Value v )
  66.   {
  67.     Assert( Value( v-1 ) < v );
  68.     start = Min( start, Value( v-1 ) );
  69.     end = Max( end, v );
  70.   }
  71.  
  72. template class Range<int8>;
  73. template class Range<uint8>;
  74. template class Range<int16>;
  75. template class Range<uint16>;
  76. template class Range<int32>;
  77. template class Range<uint32>;
  78.